<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统登录</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .login-container {
            background-color: #ffffff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
        }

        .login-container h2 {
            margin-bottom: 20px;
            color: #333;
        }

        .form-group {
            margin-bottom: 15px;
            text-align: left;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #555;
        }

        .form-group input {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        .form-group input:focus {
            border-color: #4299e1;
            outline: none;
        }

        .error {
            color: #e53e3e;
            font-size: 0.9rem;
            margin-top: 5px;
        }

        .submit-btn {
            width: 100%;
            padding: 10px;
            background-color: #4299e1;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 1rem;
        }

        .submit-btn:hover {
            background-color: #3182ce;
        }

        .auth-links {
            margin-top: 15px;
        }

        .auth-links a {
            color: #4299e1;
            text-decoration: none;
        }

        .auth-links a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h2>欢迎登录</h2>

        <!-- 全局错误提示 -->
        <div class="error" id="global-error" style="display: none;">
            用户名或密码不正确
        </div>

        <form id="login-form" method="post" action="{% url 'login' %}">
            {% csrf_token %}
            <div class="form-group">
                <label for="id_username">用户名</label>
                <input type="text" id="id_username" name="username" required>
            </div>

            <div class="form-group">
                <label for="id_password">密码</label>
                <input type="password" id="id_password" name="password" required>
            </div>

            <button type="submit" class="submit-btn">立即登录</button>
        </form>

        <!-- 辅助链接 -->
        <div class="auth-links">
            <a href="{% url 'password_reset' %}">忘记密码？</a>
            <br>
            <a href="{% url 'register' %}">注册新账户</a>
        </div>
    </div>

    <script>
        document.getElementById('login-form').addEventListener('submit', function(event) {
            var form = event.target;
            var username = form.username.value.trim();
            var password = form.password.value.trim();
            var globalError = document.getElementById('global-error');

            if (!username || !password) {
                globalError.style.display = 'block';
                event.preventDefault();
            } else {
                globalError.style.display = 'none';
            }
        });
    </script>
</body>
</html>
